#! /usr/bin/expect


set ip [lindex $argv 0]
set passwd [lindex $argv 1]
set onlyclearlog [lindex $argv 2]
set targetfile [lindex $argv 3]

set timeout 200
spawn ssh root@$ip
expect {
    "(yes/no)" {send "yes\r"; exp_continue}
    "password:" {send "$passwd\r"}
}

# git clone https://gitee.com/wanttobeamaster/ela-up /home/GoFile/src/gitee.com/wanttobeamaster/ela-up/; fi
expect  "root@*" {send "if \[ ! -d /home/GoFile/src/gitee.com/wanttobeamaster/ela-up/ \] ; then exit 1; fi\r"}

# expect  "root@*" {send "cd /home/GoFile/src/gitee.com/wanttobeamaster/ela-up; git pull origin master\r"}

expect 	"root@*" {send "$targetfile $ip\r"}

expect	{
    "only clear" {send "$onlyclearlog\r";exp_continue}
    # "whether need MAKE" {send "yes\r";exp_continue}
    "root@*" {send "exit\r"}
}

expect eof






